package com.autobet.utils;

import com.autobet.services.EnvConfigService;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by yangd on 2017-08-27.
 */
public class BetUtils {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
    private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy");
    private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMdd");
    private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd");

    public BetUtils() {
    }

    public static String getCurrDateYYYY() {
        return sdf2.format(new Date());
    }

    public static String getCurrDate() {
        return sdf.format(new Date());
    }

    public static String getCurrDateYYYYMMDD() {
        return sdf3.format(new Date());
    }

    public static String getCurrDateYYYY_MM_DD() {
        return sdf4.format(new Date());
    }

    public static String formatResult(String result) {
        byte var2 = -1;
        switch(result.hashCode()) {
            case 1537:
                if(result.equals("01")) {
                    var2 = 0;
                }
                break;
            case 1538:
                if(result.equals("02")) {
                    var2 = 1;
                }
                break;
            case 1539:
                if(result.equals("03")) {
                    var2 = 2;
                }
                break;
            case 1540:
                if(result.equals("04")) {
                    var2 = 3;
                }
                break;
            case 1541:
                if(result.equals("05")) {
                    var2 = 4;
                }
                break;
            case 1542:
                if(result.equals("06")) {
                    var2 = 5;
                }
                break;
            case 1543:
                if(result.equals("07")) {
                    var2 = 6;
                }
                break;
            case 1544:
                if(result.equals("08")) {
                    var2 = 7;
                }
                break;
            case 1545:
                if(result.equals("09")) {
                    var2 = 8;
                }
        }

        switch(var2) {
            case 0:
                return "1";
            case 1:
                return "2";
            case 2:
                return "3";
            case 3:
                return "4";
            case 4:
                return "5";
            case 5:
                return "6";
            case 6:
                return "7";
            case 7:
                return "8";
            case 8:
                return "9";
            default:
                return result;
        }
    }

    public static boolean isBig(String num) throws Exception {
        return Integer.parseInt(num) > 5;
    }

    public static boolean isSmall(String num) throws Exception {
        return Integer.parseInt(num) < 6;
    }

    public static boolean isDouble(String num) throws Exception {
        return Integer.parseInt(num) % 2 == 0;
    }

    public static boolean isBetWin(String betType, String betWhat, String betResult) throws Exception {
        int iBetResult;
        if("dx".equals(betType)) {
            iBetResult = Integer.parseInt(betResult);
            return iBetResult > 5?"D".equals(betWhat):"X".equals(betWhat);
        } else if("ds".equals(betType)) {
            iBetResult = Integer.parseInt(betResult);
            return iBetResult % 2 == 0?"S".equals(betWhat):"D".equals(betWhat);
        } else {
            throw new Exception("投注类型不正确，应该为大小或单双！");
        }
    }

    public static String getbuyWhatFromBetRule(String rule, String betType) throws Exception {
        byte var3;
        if("dx".equals(betType)) {
            var3 = -1;
            switch(rule.hashCode()) {
                case 1568:
                    if(rule.equals("11")) {
                        var3 = 0;
                    }
                    break;
                case 1569:
                    if(rule.equals("12")) {
                        var3 = 1;
                    }
                    break;
                case 1570:
                    if(rule.equals("13")) {
                        var3 = 2;
                    }
                    break;
                case 1571:
                    if(rule.equals("14")) {
                        var3 = 3;
                    }
                    break;
                case 1572:
                    if(rule.equals("15")) {
                        var3 = 4;
                    }
                case 1573:
                case 1574:
                case 1575:
                case 1576:
                case 1577:
                case 1578:
                case 1579:
                case 1580:
                case 1581:
                case 1582:
                case 1583:
                case 1584:
                case 1585:
                case 1586:
                case 1587:
                case 1588:
                case 1589:
                case 1590:
                case 1591:
                case 1592:
                case 1593:
                case 1594:
                case 1595:
                case 1596:
                case 1597:
                case 1598:
                default:
                    break;
                case 1599:
                    if(rule.equals("21")) {
                        var3 = 5;
                    }
                    break;
                case 1600:
                    if(rule.equals("22")) {
                        var3 = 6;
                    }
                    break;
                case 1601:
                    if(rule.equals("23")) {
                        var3 = 7;
                    }
                    break;
                case 1602:
                    if(rule.equals("24")) {
                        var3 = 8;
                    }
                    break;
                case 1603:
                    if(rule.equals("25")) {
                        var3 = 9;
                    }
            }

            switch(var3) {
                case 0:
                    return "X";
                case 1:
                    return "D";
                case 2:
                    return "X";
                case 3:
                    return "X";
                case 4:
                    return "D";
                case 5:
                    return "D";
                case 6:
                    return "X";
                case 7:
                    return "D";
                case 8:
                    return "D";
                case 9:
                    return "X";
                default:
                    throw new Exception("不符合投注规则！");
            }
        } else if("ds".equals(betType)) {
            var3 = -1;
            switch(rule.hashCode()) {
                case 1568:
                    if(rule.equals("11")) {
                        var3 = 0;
                    }
                    break;
                case 1569:
                    if(rule.equals("12")) {
                        var3 = 1;
                    }
                    break;
                case 1570:
                    if(rule.equals("13")) {
                        var3 = 2;
                    }
                    break;
                case 1571:
                    if(rule.equals("14")) {
                        var3 = 3;
                    }
                    break;
                case 1572:
                    if(rule.equals("15")) {
                        var3 = 4;
                    }
                case 1573:
                case 1574:
                case 1575:
                case 1576:
                case 1577:
                case 1578:
                case 1579:
                case 1580:
                case 1581:
                case 1582:
                case 1583:
                case 1584:
                case 1585:
                case 1586:
                case 1587:
                case 1588:
                case 1589:
                case 1590:
                case 1591:
                case 1592:
                case 1593:
                case 1594:
                case 1595:
                case 1596:
                case 1597:
                case 1598:
                default:
                    break;
                case 1599:
                    if(rule.equals("21")) {
                        var3 = 5;
                    }
                    break;
                case 1600:
                    if(rule.equals("22")) {
                        var3 = 6;
                    }
                    break;
                case 1601:
                    if(rule.equals("23")) {
                        var3 = 7;
                    }
                    break;
                case 1602:
                    if(rule.equals("24")) {
                        var3 = 8;
                    }
                    break;
                case 1603:
                    if(rule.equals("25")) {
                        var3 = 9;
                    }
            }

            switch(var3) {
                case 0:
                    return "D";
                case 1:
                    return "S";
                case 2:
                    return "D";
                case 3:
                    return "D";
                case 4:
                    return "S";
                case 5:
                    return "S";
                case 6:
                    return "D";
                case 7:
                    return "S";
                case 8:
                    return "S";
                case 9:
                    return "D";
                default:
                    throw new Exception("不符合投注规则！");
            }
        } else {
            throw new Exception("玩法不正确");
        }
    }

    public static String getPriBetRule(String betRule) throws Exception {
        byte var2 = -1;
        switch(betRule.hashCode()) {
            case 1568:
                if(betRule.equals("11")) {
                    var2 = 0;
                }
                break;
            case 1569:
                if(betRule.equals("12")) {
                    var2 = 1;
                }
                break;
            case 1570:
                if(betRule.equals("13")) {
                    var2 = 2;
                }
                break;
            case 1571:
                if(betRule.equals("14")) {
                    var2 = 3;
                }
                break;
            case 1572:
                if(betRule.equals("15")) {
                    var2 = 4;
                }
            case 1573:
            case 1574:
            case 1575:
            case 1576:
            case 1577:
            case 1578:
            case 1579:
            case 1580:
            case 1581:
            case 1582:
            case 1583:
            case 1584:
            case 1585:
            case 1586:
            case 1587:
            case 1588:
            case 1589:
            case 1590:
            case 1591:
            case 1592:
            case 1593:
            case 1594:
            case 1595:
            case 1596:
            case 1597:
            case 1598:
            default:
                break;
            case 1599:
                if(betRule.equals("21")) {
                    var2 = 5;
                }
                break;
            case 1600:
                if(betRule.equals("22")) {
                    var2 = 6;
                }
                break;
            case 1601:
                if(betRule.equals("23")) {
                    var2 = 7;
                }
                break;
            case 1602:
                if(betRule.equals("24")) {
                    var2 = 8;
                }
                break;
            case 1603:
                if(betRule.equals("25")) {
                    var2 = 9;
                }
        }

        switch(var2) {
            case 0:
                return "11";
            case 1:
                return "11";
            case 2:
                return "11";
            case 3:
                return "11";
            case 4:
                return "11";
            case 5:
                return "21";
            case 6:
                return "21";
            case 7:
                return "21";
            case 8:
                return "21";
            case 9:
                return "21";
            default:
                throw new Exception("不符合投注规则！");
        }
    }

    public static String getNextBetRule(String betRule) throws Exception {
        byte var2 = -1;
        switch (betRule.hashCode()) {
            case 1568:
                if (betRule.equals("11")) {
                    var2 = 0;
                }
                break;
            case 1569:
                if (betRule.equals("12")) {
                    var2 = 1;
                }
                break;
            case 1570:
                if (betRule.equals("13")) {
                    var2 = 2;
                }
                break;
            case 1571:
                if (betRule.equals("14")) {
                    var2 = 3;
                }
                break;
            case 1572:
                if (betRule.equals("15")) {
                    var2 = 4;
                }
            case 1573:
            case 1574:
            case 1575:
            case 1576:
            case 1577:
            case 1578:
            case 1579:
            case 1580:
            case 1581:
            case 1582:
            case 1583:
            case 1584:
            case 1585:
            case 1586:
            case 1587:
            case 1588:
            case 1589:
            case 1590:
            case 1591:
            case 1592:
            case 1593:
            case 1594:
            case 1595:
            case 1596:
            case 1597:
            case 1598:
            default:
                break;
            case 1599:
                if (betRule.equals("21")) {
                    var2 = 5;
                }
                break;
            case 1600:
                if (betRule.equals("22")) {
                    var2 = 6;
                }
                break;
            case 1601:
                if (betRule.equals("23")) {
                    var2 = 7;
                }
                break;
            case 1602:
                if (betRule.equals("24")) {
                    var2 = 8;
                }
                break;
            case 1603:
                if (betRule.equals("25")) {
                    var2 = 9;
                }
        }

        switch (var2) {
            case 0:
                return "12";
            case 1:
                return "13";
            case 2:
                return "14";
            case 3:
                return "15";
            case 4:
                throw new Exception("小大小小大规则已击穿");
            case 5:
                return "22";
            case 6:
                return "23";
            case 7:
                return "24";
            case 8:
                return "25";
            case 9:
                throw new Exception("大小大大小规则已击穿");
            default:
                throw new Exception("不符合投注规则！");
        }
    }


    public static String reversalBuild( String type , String buyWhat){
        if(EnvConfigService.reversal){
            if( type.equals("dx")){
                if(buyWhat.equals("D")){
                    buyWhat = "X";
                }else if(buyWhat.equals("X")){
                    buyWhat = "D";
                }

            }else if(type.equals("ds")) {
                if(buyWhat.equals("D")){
                    buyWhat = "S";
                }else if(buyWhat.equals("S")){
                    buyWhat = "D";
                }
            }
        }
        return buyWhat;
    }
}
